
package basic;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

import com.e885.log.E885Logger;

/**
 * "classpath:"是Spring自訂的url虛擬協定，這會取回一個 org.springframework.core.io.ClassPathResource實例，資源檔案是位於CLASSPATH根目錄中<br>
 * 1. resource.isOpen(): 測試檔案是否已開啟<br>
 * 2. resource.exists(): 測試檔案是否存在, 如果 "basic/MyConfig.properties" 不存在, 是不會有任何的 exception, 只會回傳 false.<br>
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class ResourceTester
{
	public ResourceTester()
	{
		ApplicationContext context = new ClassPathXmlApplicationContext( "basic/firstSpring.xml" );

		Resource resource = context.getResource( "classpath:basic/MyConfig.properties" );

		if( resource.isOpen() )
			E885Logger.testLog.debug( "file is opened" );
		else
			E885Logger.testLog.debug( "file is not opened" );

		if( resource.exists() )
			E885Logger.testLog.debug( "file is exist" );
		else
			E885Logger.testLog.debug( "file is not exist" );
	}

	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new ResourceTester();
	}

}
